package com.tl.commonlibrary.tool;

import android.text.TextUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by a on 15-3-28.
 */
public class RegexUtil {


    /**
     * 用户注册时候的匹配，只匹配汉字、半角英文、数字、下划线
     *
     * @param userName
     * @return
     */
    public static boolean isUserNameLegal(String userName) {
//        if(username.length()>16){
//            return new JsonResult(StatusCode.PARAMETERNOTLEGAL,"用户名不要超过16个字符");
//        }
        Pattern p = Pattern.compile("^[\\u4e00-\\u9fa5_a-zA-Z0-9]+$");
        Matcher matcher = p.matcher(userName);
        return matcher.find();
    }

    public static boolean isMatch(String content, String reg) {
        Pattern pattern = Pattern.compile(reg);
        Matcher matcher = pattern.matcher(content);
        return matcher.matches();
    }

    public static boolean isPhoneNumber(String phoneNumber) {
        if (TextUtils.isEmpty(phoneNumber)) {
            return false;
        }
        return isMatch(phoneNumber, "\\d{11}");
    }
}
